﻿/*
*   题库列表页面
*/
angular.module('jisuStuHome')
.filter('is_null', ['$sce',
function ($sce) {
    return function (text) {
        if (text == undefined || text == null || text == "") {
            return 0;
        } else {
            return text;
        }
    };
} ])

.controller('stuQueList', ['$rootScope','$scope', '$stateParams', '$state', 'StuRequestTrain', 'sysUserInfo', 'Msg', 'T', 'LS', function ($rootScope,$scope, $stateParams, $state, ST, sysUserInfo, Msg, T, LS) {      
    $scope.isNotNull = function (txt) {
        if (txt == undefined || txt == null || txt == "") {
            return false;
        }
        return true;
    }        

    $scope.ishome=true;//是第一页
    // 是否显示头手机或者课程
    if($scope.isNotNull($stateParams.userId)){            
           $rootScope.headerShow = false;
           if(document.getElementById("kefu"))
           document.getElementById("kefu").remove();
           if(document.getElementById("topbar"))
           document.getElementById("topbar").remove();
           if(document.getElementById("fileUploadList"))
           document.getElementById("fileUploadList").remove();
    }else{
           $rootScope.headerShow = true;
    }

    $scope.typeId = $stateParams.typeId;
    $scope.knowledgeName = $stateParams.knowledgeName;
    // 打开错题列表，收藏列表
    $scope.playOpenList = function (typeId) {        
        $stateParams.typeId = typeId;
        $state.go('home.stuquelist', $stateParams,{reload:true});
    }
    // 转换时间
    $scope.formatDuring = function(mss) {
        var days = parseInt(mss / ( 60 * 60 * 24));
        var hours = parseInt((mss % (60 * 60 * 24)) / (60 * 60));
        var minutes = parseInt((mss % ( 60 * 60)) / 60);
        var seconds = mss % 60;
        return days + " 天 " + hours + " 小时 " + minutes + " 分钟 " + seconds + " 秒 ";
    }
    // 返回按钮
    $scope.back =function(){
        if($scope.isNotNull($stateParams.backUrl) && $stateParams.backUrl == "phone"&&location.hash.indexOf("token")==-1){
            window.location.href = "/app/peixun/info.html?arrangeId="+$stateParams.xid;
        }else{
            history.back();
        }
    }
    // 返回父级
    $scope.playParent = function(){
        $stateParams.knowledgeId  = $stateParams.parentId;
        $stateParams.knowledgeName = $stateParams.parentName;
        $state.go('home.stuquelist', $stateParams,{reload:true});
    }
    console.log($stateParams.xid);
    // 初始化参数
    $scope.init = function () {
        // 判断内容
        if (!$scope.isNotNull($stateParams.knowledgeId)) {
            Msg.info('提示', '知识结构id缺少');
        }
        // 参数处理 判断参数存不存在
        if ($scope.isNotNull($stateParams.knowledgeId)) {
            LS.setLS(sysUserInfo.getuserinfo().user_ID + '_stuQueList', $stateParams);
        } else {
            $stateParams = LS.getLS(sysUserInfo.getuserinfo().user_ID + '_stuQueList');
            if (!$scope.isNotNull($stateParams.knowledgeId)) {
                Msg.info('未知的跳转');
            }
        }
        // 题目组
        $scope.questionsGroup = [];
        // 每组题目数
        $scope.questionsEach = 40;
        // 题库选中的组
        $scope.selectKey = 1;
        // 非正常答题的时候
        if($scope.typeId != 0){
            var selKey =  LS.getLS("zu_"+sysUserInfo.getuserinfo().organization_ID + '_' + sysUserInfo.getuserinfo().user_ID + '_' + $stateParams.knowledgeId + '_' + $stateParams.xid + '_' + $scope.typeId);
            if($scope.isNotNull(selKey)){
                $scope.selectKey = selKey;
                console.log("记录上次的答题组是："+selKey);
            }
        }
        // 返回对象
        $scope.userQuestionsInfo = {
            // 总数
            totleQuestion: 0,
            // 已答
            doCount: 0,
            // 未答
            dontCount: 0,
            // 正确率
            correctRate: 0,
            // 总时长
            totleTime: 0,
            // 知识结构
            knowledge:null,                
        };
        // loading
        $scope.queLoading = false;
        // 请求参数
        $scope.queListParams = {
            // 知识结构id
            knowledgeId: $stateParams.knowledgeId,
            // 组织机构id
            organizationId: sysUserInfo.getuserinfo().organization_ID,
            // 用户id
            userId: sysUserInfo.getuserinfo().user_ID,

            // 入口 （1,任务 2,课程 3,试卷 4,题库）
            opType: 1,
            // 任务id、课程id、试卷id、题库id
            searchId: $stateParams.xid
        }
        if ($scope.typeId  == 1) {  // 错题
            $scope.questionsChildCount = 0;
            $scope.getUserErrQuestionsInfo();    
        }else if($scope.typeId  == 2){// 收藏
            $scope.questionsChildCount = 0;
            $scope.getUserCollQuestionsInfo();
        }else{
            // 发送正常练习请求
            $scope.getUserQuestionsInfo();
        }    
        //  随机抽题参数 （部分参数在这边没有用）
        $scope.getSmartQueParams = {
            knowledgeId:$stateParams.knowledgeId,
            userId:sysUserInfo.getuserinfo().user_ID,   // 用户id 
            organizationId:sysUserInfo.getuserinfo().organization_ID,   // 企业id
            queType:[-1], // 题目类型
            difficulty:[-1],    // 题目难度
            queNum:40 // 题目数量
        }    
    }
    /********************错题练习请求**********************/
    $scope.getUserErrQuestionsInfo = function(){
        $scope.queLoading = true;
        ST.findKnowledgeQuestion($scope.queListParams).then(function(response){
            $scope.queLoading = false;
            if(response.errorcode == 0){
                $scope.userQuestionsInfo = response.datas[0];
                if($scope.isNotNull(response.datas[0])){                
                    $scope.userQuestionsInfo.totleQuestion = response.datas[0].errorNum;
                    $scope.userQuestionsInfo.knowledge = response.datas[0].knowledgeInfo; 
                    $scope.handResCollData();
                }               
                
            }
        });
    }    
    /********************题目收藏请求**********************/
    $scope.getUserCollQuestionsInfo = function(){
        $scope.queLoading = true;
        ST.findCollections($scope.queListParams).then(function(response){
            $scope.queLoading = false;
            if(response.errorcode == 0){
                $scope.userQuestionsInfo = response.datas[0];
                if($scope.isNotNull(response.datas[0])){                
                    $scope.userQuestionsInfo.totleQuestion = response.datas[0].collection;
                    $scope.userQuestionsInfo.knowledge = response.datas[0].knowledgeInfo; 
                    $scope.handResCollData();
                }               
                
            }
        });
    }
    // 处理收藏返回的信息
    $scope.handResCollData = function(){
        var groupNum = parseInt($scope.userQuestionsInfo.totleQuestion / $scope.questionsEach);
        for (var i = 0; i <= groupNum; i++) {                  
            if (i == groupNum && (i + 1) * $scope.questionsEach > $scope.userQuestionsInfo.totleQuestion) {
                $scope.questionsGroup.push({ key: i + 1, value: (i * $scope.questionsEach + 1) + '-' + $scope.userQuestionsInfo.totleQuestion, doneFlag: false });
            } else {
                $scope.questionsGroup.push({ key: i + 1, value: (i * $scope.questionsEach + 1) + '-' + ((i + 1) * $scope.questionsEach), doneFlag: false });
            }

        }
              
    }
    $scope.questionCount=0;
    // 子集中带返回
    $scope.backBtn = false;
    /********************正常练习**********************/
    //  获取用户题库的练习信息
    $scope.getUserQuestionsInfo = function () {
        $scope.queLoading = true;
        // 请求数据
        ST.getQuesTotleInfo($scope.queListParams).then(function (response) {
            $scope.queLoading = false;
            if (response.errorcode == 0) {
                $scope.userQuestionsInfo = response.data;
                $scope.getTotleQuestion();                
                //  遍历直接子节点信息
                if($stateParams.knowledgeId == $stateParams.parentId){  // 判断是否是从子集进去的                                                        
                    $scope.forChildQuestionsInfo();
                }else{ // 赋值时长
                    $scope.userQuestionsInfo.totleTime = $stateParams.totleTime;
                    $scope.backBtn = true;    
                    $scope.ishome=false;
                    // 子集数量赋值空
                    $scope.questionsChildCount = 0;
                }
            } else {
                Msg.error('提示', '获取题库信息失败！');
            }
        });
    }
    //获取当前分类的总题数
    $scope.getTotleQuestion=function(){
         ST.getQuesTotleInfo({
            knowledgeId: $stateParams.knowledgeId,
            organizationId: sysUserInfo.getuserinfo().organization_ID,
            userId: sysUserInfo.getuserinfo().user_ID,
            opType: 4,
            searchId: $stateParams.xid
        }).then(function (response) {   
            if (response.errorcode == 0&&response.data!=null&&response.data.totleQuestion!=undefined) {    
                $scope.userQuestionsInfo.totleQuestion=response.data.totleQuestion;
                $scope.handleResParams();
            }
         },function(e){

         });
    }


    // 选中某个组
    $scope.selGroup = function (key) {
        $scope.selectKey = key;
    }
    // 处理返回回来的参数
    $scope.handleResParams = function () {
        $scope.questionsGroup = [];
        //$scope.userQuestionsInfo.totleQuestion = 111320;
        var numParams = {
            knowledgeId: $stateParams.knowledgeId,
            xid: $stateParams.xid,
            userId: sysUserInfo.getuserinfo().user_ID,
            orgId: sysUserInfo.getuserinfo().organization_ID
        };

        // 获取答过的题目组
        ST.findGroupNumber(numParams).then(function (response) {
            var resData = response.datas
            // 遍历题目的列表 
            //if ($scope.isNotNull(resData)) {
            var groupNum = parseInt($scope.userQuestionsInfo.totleQuestion / $scope.questionsEach);
            // 首先记录上次答题的组数
            if(resData!=null&&resData!=undefined&&resData.length > 0){
                $scope.selectKey = parseInt(resData[0].groupRecord);    
            }else{
                resData=[];
            }            
            console.log('上一次顺序答题的记录'+$scope.selectKey);
            if ($scope.userQuestionsInfo.totleQuestion > 0) {
                for (var i = 0; i <= groupNum; i++) {
                    var doneFlag = false;   // 找出选中的
                    angular.forEach(resData, function (data, index) {
                        if (parseInt(data.groupRecord) == (i + 1)) {
                            doneFlag = true;
                        }
                    });
                    if (i == groupNum && (i + 1) * $scope.questionsEach > $scope.userQuestionsInfo.totleQuestion) {
                        $scope.questionsGroup.push({ key: i + 1, value: (i * $scope.questionsEach + 1) + '-' + $scope.userQuestionsInfo.totleQuestion, doneFlag: doneFlag });
                    } else {
                        $scope.questionsGroup.push({ key: i + 1, value: (i * $scope.questionsEach + 1) + '-' + ((i + 1) * $scope.questionsEach), doneFlag: doneFlag });
                    }

                }
            }
            //}
        });

        // 计算正确率
        if ($scope.isNotNull($scope.userQuestionsInfo.alltotleCount) && $scope.userQuestionsInfo.alltotleCount != 0) {
            $scope.userQuestionsInfo.correctRate = parseInt(($scope.userQuestionsInfo.allcorrotCount / $scope.userQuestionsInfo.alltotleCount) * 100);
        } else {
            $scope.userQuestionsInfo.correctRate = 0;
        }

        // 计算题目正确率
        if ($scope.isNotNull($scope.userQuestionsInfo.totleQuestion) && $scope.userQuestionsInfo.totleQuestion != 0) {
            $scope.userQuestionsInfo.allcorrectRate = parseInt(($scope.userQuestionsInfo.allcorrotQuestionCount / $scope.userQuestionsInfo.totleQuestion) * 100);
        } else {
            $scope.userQuestionsInfo.allcorrectRate = 0;
        }

    }
    /******************智能抽题**********************/
    // 智能抽题是否显示
    $scope.smartQueShow = false;
    // 题目类型
    $scope.queTypeList = [  
        {value:-1,name:'随机生成',flag:true},
        {value:1,name:'单选题',flag:false},
        {value:2,name:'多选题',flag:false},
        {value:3,name:'判断题',flag:false},
        {value:4,name:'问答题',flag:false},
        {value:5,name:'填空题',flag:false},
        {value:6,name:'B型题',flag:false},
        {value:7,name:'综合题',flag:false}
    ];
    //  难度 1 2 3 
    $scope.queDifficultyList = [
        {value:-1, name:'随机生成',flag:true},
        {value:1, name:"简单题", flag:false},
        {value:2, name:"一般题", flag:false},
        {value:3, name:"困难题", flag:false}    
    ];
    // 切换选项 -1 类型随机 0 难度随机
    $scope.switchTypeQue = function(obj){
        obj.flag = !obj.flag;
        if(obj.value == -1 && obj.flag){                        
            angular.forEach($scope.queTypeList,function(data,index){
                if(data.value != -1){
                    data.flag = false;    
                }                
            });
        }else{
            $scope.queTypeList[0].flag = false;            
        }  
        $scope.getCountBydifficult();              
    }    
    // 切换难度选项
    $scope.switchDiffQue = function(obj){
        obj.flag = !obj.flag;
        if(obj.value == -1 && obj.flag){                                   
            angular.forEach($scope.queDifficultyList,function(data,index){
                if(data.value != -1){
                    data.flag = false;    
                }                
            });           
        }else{           
            $scope.queDifficultyList[0].flag = false;            
        }
        $scope.getCountBydifficult();                     
    }    
    // 子集智能抽题用到
    $scope.smartChildObj = null;
    //  智能抽题
    $scope.smartQue = function(obj){        
        // 初始化参数
        angular.forEach($scope.queTypeList,function(data,index){
            data.flag = false;            
        });
        $scope.queTypeList[0].flag=true;
        // 难度        
        angular.forEach($scope.queDifficultyList,function(data,index){           
            data.flag = false;    
        });  
        $scope.queDifficultyList[0].flag=true;
        if($scope.isNotNull(obj)){
            obj.totleTime = $scope.userQuestionsInfo.totleTime;
            $scope.smartChildObj = obj;
            // 子集抽题
            $scope.getSmartQueParams.knowledgeId = obj.knowledge.knowledge_Id;
            $scope.questionCount=$scope.smartChildObj.totleQuestion;
        }else{
            $scope.questionCount=$scope.userQuestionsInfo.totleQuestion;
            $scope.getSmartQueParams.knowledgeId = $stateParams.knowledgeId;
        }
        $scope.smartQueShow = true;
    }
    // 关闭抽题
    $scope.closeQue = function(){
        // 赋值空
        $scope.smartChildObj = null;

        $scope.smartQueShow = false;
    }
    
    // 0 没有任何选择 1 40题   2 80题 
    $scope.smartQueflag = 0;     
    
    // 智能抽题请求
    $scope.smartRequest = function(){
        if(parseInt($scope.getSmartQueParams.queNum) <= 0 ){        
            Msg.info('提示','请选择题目数量');
            return;
        }           
        // 类型
        $scope.getSmartQueParams.queType = [];
        angular.forEach($scope.queTypeList,function(data,index){
            if(data.flag)
            $scope.getSmartQueParams.queType.push(data.value);            
        });
        if($scope.getSmartQueParams.queType.length <= 0){        
            Msg.info('提示','请选择题目类型');
            return;
        }        
        // 难度
        $scope.getSmartQueParams.difficulty=[];
        angular.forEach($scope.queDifficultyList,function(data,index){
            if(data.flag)
            $scope.getSmartQueParams.difficulty.push(data.value);        
        })  
        if($scope.getSmartQueParams.difficulty.length <= 0){
            Msg.info('提示','请选择题目难度');
            return;
        }                               
        if($scope.isNotNull($scope.smartChildObj)){ // 子集智能
            // 参数放入本地缓存
            LS.setLS(sysUserInfo.getuserinfo().user_ID + '_stuQueInfo', { userQuestionsInfo: $scope.smartChildObj, groupIndex: 1, groupPath: $scope.getSmartQueParams.queNum,stuQueList:{ xid: $stateParams.xid, knowledgeId:$scope.smartChildObj.knowledge.knowledge_Id,typeId:0, knowledgeName:$scope.smartChildObj.knowledge.knowledge_Name,arrangeId:$stateParams.arrangeId, parentId:$stateParams.parentId,parentName:$stateParams.parentName,parentCount:$stateParams.parentCount},smartQueParams:$scope.getSmartQueParams,backUrl:$stateParams.backUrl });
        }else{
            // 参数放入本地缓存
            LS.setLS(sysUserInfo.getuserinfo().user_ID + '_stuQueInfo', { userQuestionsInfo: $scope.userQuestionsInfo, groupIndex: 1, groupPath: $scope.getSmartQueParams.queNum,stuQueList:$stateParams,smartQueParams:$scope.getSmartQueParams });
        }
        
        // 跳转页面
        $state.go('home.stuqueinfo');
    }


     // 智能抽题选择难度和题目类型  获取题目数
    $scope.getCountBydifficult = function(){      
        // 类型
        $scope.getSmartQueParams.queType = [];
        angular.forEach($scope.queTypeList,function(data,index){
            if(data.flag)
            $scope.getSmartQueParams.queType.push(data.value);            
        });
        if($scope.getSmartQueParams.queType.length <= 0){        
            Msg.info('提示','请选择题目类型');
            return;
        }        
        // 难度
        $scope.getSmartQueParams.difficulty=[];
        angular.forEach($scope.queDifficultyList,function(data,index){
            if(data.flag)
            $scope.getSmartQueParams.difficulty.push(data.value);        
        })  
        if($scope.getSmartQueParams.difficulty.length <= 0){
            Msg.info('提示','请选择题目难度');
            return;
        }                               
        //请求
        ST.getQuestionCount($scope.getSmartQueParams).then(function (response) {

            if (response.errorcode == 0) {
                $scope.questionCount=response.data;
            } else {
                Msg.error('提示', '获取题库信息失败！');
            }
        });


    }
    /**********查询子分类*************/    
    var option = {
            
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                x: 'center',
                y:290,
                data: ['完成度(%)', '正确率(%)']
            },
                color:['#3399ff','#ff6666'],
            radar: [
                {
                    indicator: [],//{ name: '数学', max: 100}
                    center: ['50%', '50%'],                   
                    //radius: 90.5
                }
            ],
            series: [
                {
                    type: 'radar',
                    tooltip: {
                        trigger: 'item'
                    },
                    itemStyle: {normal: {areaStyle: {type: 'default'}}},
                    data: [
                        {
                            value: [],
                            name: '完成度(%)'
                        }, {
                            value: [],
                            name: '正确率(%)'
                        }
                    ]
                }
            ]
        };
    // 项目
    var objectKnow = option.radar[0].indicator;
    // 画布大小
    var radiusSize = option.radar[0].radius;
    // 完成度
    var objectComplet = option.series[0].data[0].value;
    // 正确率
    var objectSuccess = option.series[0].data[1].value;
    // 子集题库的练习详细信息
    $scope.questionsChildInfoList = [];
    // 显示下属子集
    $scope.questionsChildCount = 1;
    // 处理子节点信息
    $scope.forChildQuestionsInfo = function(){   
        // 隔离父节点的参数
        $scope.queListChildParams = angular.copy($scope.queListParams);    
        $scope.params = {
            userId: sysUserInfo.getuserinfo().user_ID,
            startDate: "",    // 起始时间
            endDate: "", // 结束时间
            searchName: "", //搜索内容 
            knowledge_Id:  $scope.queListChildParams.knowledgeId, // 子集搜索// 父级节点参数
            orgId: sysUserInfo.getuserinfo().organization_ID,   // 企业id
            org_Name: sysUserInfo.getuserinfo().organization_Name,   // 企业id
            powerLV: 2 //登录人的系统角色         
        };
        ST.findKnowledgeList($scope.params).then(function (response) {  // then                
            if (response.errorcode == "0") {          
                //创建画布
                var abilityObj = document.getElementById("abilityData");
                var abilityChart = echarts.init(abilityObj);                           
                // 子节点目前都是单独拆出来的
                $scope.queListChildParams.opType  = 4;
                // 子集的数量
                $scope.questionsChildCount = response.datas.length;                
                // 异步获取子集详细信息
                angular.forEach(response.datas,function(cdata,cindex){                    
                    $scope.queListChildParams.knowledgeId = cdata.knowledge_Id;                    
                    // 请求数据
                    ST.getQuesTotleInfo($scope.queListChildParams).then(function (response) {   
                        if (response.errorcode == 0) {                            
                            // 修改画布信息
                            var queObjInfo = response.data;                               
                            // 赋值项目
                            if(cindex <10){
                                objectKnow.push({ name: queObjInfo.knowledge.knowledge_Name, max: 100});
                            }
                            // 赋值完成度
                            if ($scope.isNotNull(queObjInfo.totleQuestion) && queObjInfo.totleQuestion != 0) {
                                queObjInfo.allcorrectRate = parseInt((queObjInfo.allcorrotQuestionCount / queObjInfo.totleQuestion) * 100);
                                if(cindex <10){
                                    objectComplet.push(queObjInfo.allcorrectRate);
                                }
                            } else {
                                if(cindex <10){
                                    objectComplet.push(0);
                                }
                            }                                                        
                            // 赋值正确率
                            if ($scope.isNotNull(queObjInfo.alltotleCount) && queObjInfo.alltotleCount != 0) {
                                queObjInfo.correctRate = parseInt((queObjInfo.allcorrotCount / queObjInfo.alltotleCount) * 100);
                                if(cindex <10){
                                    objectSuccess.push(queObjInfo.correctRate);    
                                }
                            } else {
                                if(cindex <10){
                                    objectSuccess.push(0);                                
                                }
                            }  
                            // 处理总时长
                            if (!$scope.isNotNull(queObjInfo.totleTime)) {
                                queObjInfo.totleTime = 0
                            }
                            $scope.userQuestionsInfo.totleTime +=queObjInfo.totleTime;
                            queObjInfo.knowledge_Name = queObjInfo.knowledge.knowledge_Name;    
                            // 处理父级参数
                            $scope.countParent(queObjInfo);
                            // 子集存储进去
                            $scope.questionsChildInfoList.push(queObjInfo);      
                            if($scope.questionsChildCount <= $scope.questionsChildInfoList.length){
                                $scope.questionsChildInfoList = $scope.bubbleSort($scope.questionsChildInfoList);
                            }
                            // 图面的大小每多一个减小0.5%
                            radiusSize = 100 - objectKnow.length *0.3;
                            if(radiusSize < 50){
                                radiusSize = 50;
                            }
                            if(cindex <10){
                                // 重新赋值不然没有效果
                                option.radar[0].radius = radiusSize;                           
                                // 渲染
                                abilityChart.setOption(option, true);                                                                                                                                                   
                            }
                        }
                    });             
                });                                                                                    
            }
        });
    };    
    // 完毕后进行排序
    $scope.bubbleSort = function(arr) {
        var len = arr.length;
        for (var i = 0; i < len; i++) {
            for (var j = 0; j < len - 1 - i; j++) {
                if (parseInt(arr[j].knowledge.sortCode) > parseInt(arr[j+1].knowledge.sortCode)) {        //相邻元素两两对比
                    var temp = arr[j+1];        //元素交换
                    arr[j+1] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        return arr;
    }
    // 累计父级的总数
    $scope.countParent = function(chile){    
        // 最后一次正确数
        if (!$scope.isNotNull(chile.allcorrotQuestionCount)) {
            chile.allcorrotQuestionCount = 0;
        }
        // 总数（除数可不做判断）
        if (!$scope.isNotNull(chile.totleQuestion)) {
            chile.totleQuestion = 0;
        }
        // 正确次数
        if (!$scope.isNotNull(chile.allcorrotCount)) {
            chile.allcorrotCount = 0;
        }
        // 总做题次数
        if (!$scope.isNotNull(chile.alltotleCount)) {
            chile.alltotleCount = 0;
        }
        // 已答题目数
        if(!$scope.isNotNull(chile.doCount)){
            chile.doCount = 0;
        }
        // 未答题目数
        if(!$scope.isNotNull(chile.dontCount)){
            chile.dontCount = 0;
        }
        // 最后一次正确数
        if ($scope.isNotNull($scope.userQuestionsInfo.allcorrotQuestionCount) && $scope.userQuestionsInfo.allcorrotQuestionCount != 0) {
            $scope.userQuestionsInfo.allcorrotQuestionCount += chile.allcorrotQuestionCount;
        }else{
            $scope.userQuestionsInfo.allcorrotQuestionCount = 0 + chile.allcorrotQuestionCount;
        }
        // // 总数（除数可不做判断）
        // if ($scope.isNotNull($scope.userQuestionsInfo.totleQuestion) && $scope.userQuestionsInfo.totleQuestion != 0) {
        //     $scope.userQuestionsInfo.totleQuestion += chile.totleQuestion;
        // }else{
        //     $scope.userQuestionsInfo.totleQuestion = 0+chile.totleQuestion;
        // }
        // 正确次数
        if ($scope.isNotNull($scope.userQuestionsInfo.allcorrotCount) && $scope.userQuestionsInfo.allcorrotCount != 0) {
            $scope.userQuestionsInfo.allcorrotCount += chile.allcorrotCount;
        }else{
            $scope.userQuestionsInfo.allcorrotCount = 0+ chile.allcorrotCount;
        }
        // 总做题次数
        if ($scope.isNotNull($scope.userQuestionsInfo.alltotleCount) && $scope.userQuestionsInfo.alltotleCount != 0) {
            $scope.userQuestionsInfo.alltotleCount += chile.alltotleCount;
        }else{
            $scope.userQuestionsInfo.alltotleCount = 0 + chile.alltotleCount;
        }      
        // 总已答题目数
        if ($scope.isNotNull($scope.userQuestionsInfo.doCount) && $scope.userQuestionsInfo.doCount != 0) {
            $scope.userQuestionsInfo.doCount += chile.doCount;
        }else{
            $scope.userQuestionsInfo.doCount = 0 + chile.doCount;
        }      
        // 总未答题目数
        if ($scope.isNotNull($scope.userQuestionsInfo.dontCount) && $scope.userQuestionsInfo.dontCount != 0) {
            $scope.userQuestionsInfo.dontCount += chile.dontCount;
        }else{
            $scope.userQuestionsInfo.dontCount = 0 + chile.dontCount;
        }        

        // 计算正确率
        if ($scope.isNotNull($scope.userQuestionsInfo.alltotleCount) && $scope.userQuestionsInfo.alltotleCount != 0) {
            $scope.userQuestionsInfo.correctRate = parseInt(($scope.userQuestionsInfo.allcorrotCount / $scope.userQuestionsInfo.alltotleCount) * 100);
        } else {
            $scope.userQuestionsInfo.correctRate = 0;
        }

        // 计算题目正确率
        if ($scope.isNotNull($scope.userQuestionsInfo.totleQuestion) && $scope.userQuestionsInfo.totleQuestion != 0) {
            $scope.userQuestionsInfo.allcorrectRate = parseInt(($scope.userQuestionsInfo.allcorrotQuestionCount / $scope.userQuestionsInfo.totleQuestion) * 100);
        } else {
            $scope.userQuestionsInfo.allcorrectRate = 0;
        }        
        $stateParams.parentCount = $scope.userQuestionsInfo.totleQuestion;
    }
    // 放大图表
    $scope.enlargeShow = false;
    $scope.enlargeOpen = function(){        
        var enlargeData = document.getElementById("enlargeData");
        var enlargeChar = echarts.init(enlargeData);    
        // 标题位置
        option.legend.y = 20;
        // 大小   
        delete option.radar[0].radius
        enlargeChar.setOption(option, true);           
        $scope.enlargeShow = true;
    }
    $scope.enlargeClose = function(){
      $scope.enlargeShow = false;
    }     
    // 打开子集页面
    $scope.openChild = function(know,taskObj){
        if($scope.isNotNull(taskObj)){// 顶级的
            $state.go('home.stuquelist',{ xid: taskObj.id, knowledgeId:know.knowledge_Id,typeId:0, knowledgeName:know.knowledge_Name,arrangeId:$stateParams.arrangeId,parentId:know.knowledge_Id,parentName:know.knowledge_Name,parentCount:$scope.userQuestionsInfo.totleQuestion,totleTime:$scope.userQuestionsInfo.totleTime,backUrl: $stateParams.backUrl});             
        }else{// 子集
            $state.go('home.stuquelist',{ xid: $stateParams.xid, knowledgeId:know.knowledge_Id,typeId:0, knowledgeName:know.knowledge_Name,arrangeId:$stateParams.arrangeId,parentId:$stateParams.parentId,parentName:$stateParams.parentName,parentCount:$stateParams.parentCount,totleTime:$scope.userQuestionsInfo.totleTime,backUrl: $stateParams.backUrl});            
        }        
    }    
    // 子节点的错题练习
    $scope.childError = function(know){
        $state.go('home.stuquelist',{ xid: $stateParams.xid, knowledgeId:know.knowledge_Id,typeId:1, knowledgeName:know.knowledge_Name,arrangeId:$stateParams.arrangeId,parentId:$stateParams.parentId,parentName:$stateParams.parentName,parentCount:$stateParams.parentCount,totleTime:$scope.userQuestionsInfo.totleTime,backUrl: $stateParams.backUrl} ,{reload:true});
    }

    // 子集跳转到题目答题
    $scope.btnRequestChild = function(obj){
        obj.totleTime = $scope.userQuestionsInfo.totleTime;
        if(obj.totleQuestion <=0){
            Msg.info("提示","此题库下没有题目");
            return;
        }
     // 参数放入本地缓存
        LS.setLS(sysUserInfo.getuserinfo().user_ID + '_stuQueInfo', { userQuestionsInfo:obj, groupIndex:1, groupPath: $scope.questionsEach,stuQueList:{ xid: $stateParams.xid, knowledgeId:obj.knowledge.knowledge_Id,typeId:0, knowledgeName:obj.knowledge.knowledge_Name,arrangeId:$stateParams.arrangeId,parentId:$stateParams.parentId,parentName:$stateParams.parentName,parentCount:$stateParams.parentCount,totleTime:$scope.userQuestionsInfo.totleTime,backUrl: $stateParams.backUrl,passtype:$stateParams.passtype,pass:$stateParams.pass}});
        // 跳转页面
        $state.go('home.stuqueinfo');
    }
    // 请求服务器
    $scope.btnRequest = function () {
        if ($scope.selectKey == 0|| isNaN($scope.selectKey) || $scope.selectKey.toString().indexOf('ZN_') != -1) {
            Msg.info('提示', '请选择组');
            return;
        }
        // 参数放入本地缓存
        LS.setLS(sysUserInfo.getuserinfo().user_ID + '_stuQueInfo', { userQuestionsInfo: $scope.userQuestionsInfo, groupIndex: $scope.selectKey, groupPath: $scope.questionsEach,stuQueList:$stateParams });
        // 跳转页面
        $state.go('home.stuqueinfo');
    }

    // 判断是否为空
    $scope.isNull = function (num, def) {
        if (num == undefined || num == null || num == "" || num == 'NaN') {
            num = def
        }
        return num;
    }

    $scope.init();
} ]);

